package com.ruoyi.yljf.controller.AppController;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.security.annotation.Anonymous;
import com.ruoyi.yljf.domain.dto.ActiveDTO;
import com.ruoyi.yljf.domain.dto.UserBindVXDTO;
import com.ruoyi.yljf.domain.dto.UserLoginDTO;
import com.ruoyi.yljf.domain.dto.UserRegisterDTO;
import com.ruoyi.yljf.service.IUserService;
import com.ruoyi.yljf.service.MSGService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;


/**
 * 用户登录注册接口
 * 无需token
 *
 * @author metaee
 * &#064;date  2025-01-07
 */
@Anonymous
@RequestMapping("/api/user")
@RestController
public class ApiUserController extends BaseController {

    @Autowired
    private IUserService userService;
    @Autowired
    private MSGService msgService;

    /**
     * 用户手机号注册
     */
    @PostMapping("/signIn")
    public AjaxResult signIn(@Validated @RequestBody UserRegisterDTO request) {
        return userService.signIn(request);
    }


    /**
     * 用户登录--手机号和验证码登录和微信登录
     */
    @PostMapping("/login")
    public AjaxResult login(@RequestBody UserLoginDTO request) {
        return userService.login(request);

    }
    

    /**
     * 绑定VX
     */
    @PostMapping("/bingVX")
    public AjaxResult bindVX(@RequestBody UserBindVXDTO request){
        return userService.bindVX(request);
    }

    
    /**
     * 发送短信验证码
     */
    @GetMapping("send/{phone}/interAspect")
    public AjaxResult sendMsm(@PathVariable String phone) {
        msgService.send( phone);
        return success("验证码发送成功!");
    }

    /**
     * token登录
     */
    @PostMapping("/tokenLogin")
    public AjaxResult tokenLogin(@RequestBody UserLoginDTO dto){
        return userService.tokenLogin(dto);
    }

    /**
     * 排序测试
     */
    @PostMapping("/test")
    public AjaxResult test(ActiveDTO dto) {
        return success();
    }


    @GetMapping("/loginOut")
    public AjaxResult loginOut(HttpServletRequest req) {
        return userService.loginOut(req);
    }

}
